<template>
  <div>
    <div id="cavans" style="margin:5px;float:left;height: 100%">
    </div>
    <b-form-group>
      <!-- 属性设置 -->
      <b-form class="pform" ref="ParamConfigForm" id="param_config_form" style="float: right; width:400px;">
        <div class="form_title">属性设置</div>
        <div class="form_content">
          <table>
            <tr>
              <td class="th">ID：</td>
              <td>
                <b-form-input type="text" size="sm" disabled style="width:200px" v-model="currentSelectedModel.id" />
              </td>
            </tr>
            <tr>
              <td class="th">名称：</td>
              <td>
                <b-form-input type="text" size="sm" disabled style="width:200px" v-model="currentSelectedModel.name" />
              </td>
            </tr>
          </table>
        </div>
        <div class="form_btn_div">
        </div>
      </b-form>
      <!-- 初始化参数 -->
      <b-form class="pform" ref="InitParamConfigForm" id="init_param_config_form" style="float: right; width:400px;" v-show="initParamConfigForm.show">
        <div class="form_title">初始化参数配置</div>
        <!-- 这边是显示数据的表 -->
        <div class="form_content">
          <b-table striped hover style="min-height: 40px" :items="initParamConfigForm.store" :fields="initParamConfigForm.fields">
            <template slot="operation" slot-scope="row">
              <b-btn size="sm" @click="showInitParamConfigFormChangeModal(row.item)" class="float-right" variant="primary" style="font-size: 0.3rem;padding: 0.15rem 0.4rem;">
                修改
              </b-btn>
              <b-btn size="sm" @click="deleteInitParam(row.item)" class="float-right" variant="primary" style="font-size: 0.3rem;padding: 0.15rem 0.4rem;">
                删除
              </b-btn>
            </template>
          </b-table>
        </div>
        <div class="form_btn_div">
          <table>
            <tr>
              <td class="th">参数名</td>
              <td>
                <b-form-input type="text" size="sm" style="width:200px" v-model="initParamConfigForm.value" />
              </td>
            </tr>
            <tr>
              <td class="th">参数定值</td>
              <td>
                <b-form-input type="text" size="sm" style="width:200px" v-model="initParamConfigForm.type" />
              </td>
            </tr>
          </table>
          <!-- Event:添加按钮单击事件 addInitParam() -->
          <b-button variant="success" style="width:200px; margin:5px;" @click="addInitParam()" size="sm">添加</b-button>
        </div>
      </b-form>
      <!-- 网元能力入参配置 -->
      <b-form class="pform" ref="NetworkInputParamConfigForm" id="network_input_param_config_form" style="float: right; width:400px;" v-show="networkInputParamConfigForm.show">
        <div class="form_title">网元能力入参配置</div>
        <div class="form_content">
          <table id="branchview">
            <tr v-for="goods in networkInputParamConfigForm.store">
              <td class="th">
                {{goods.namelistauto}}
              </td>
              <td>
                <b-form-select @input="selectionOrigin(goods.select.selected,goods.namelistauto)" v-model="goods.select.selected" :options="goods.select.options" size="sm" />
              </td>
            </tr>
          </table>
        </div>
        <div class="form_btn_div">
        </div>
      </b-form>
      <!-- 网元能力条件 -->
      <b-form class="pform" ref="NetWorkConditionForm" id="network_condition_form" style="float: right; width:400px;" v-show="netWorkConditionForm.show">
        <div class="form_title">网元能力条件</div>
        <div class="form_content">
          <table id="conditionview">
            <tr v-for="goods in netWorkConditionForm.store">
              <td class="th">
                {{goods.key}}:
              </td>
              <td>
                {{goods.text}}
              </td>
              <td @click="showNodeDel(goods.text)" style="color: red">&nbsp;删除</td>
            </tr>
          </table>
        </div>
        <div class="form_btn_div">
        </div>
      </b-form>
      <!-- 网元能力条件配置 -->
      <b-form class="pform" ref="NetWorkConditionConfigForm" id="network_condition_config_form" style="float: right; width:400px;" v-show="netWorkConditionConfigForm.show">
        <div class="form_title">网元能力条件配置</div>

        <div class="form_content">
          <table>
            <tr>
              <td class="th">拼接条件：</td>
              <td>
                <b-form-select size="sm" v-model="netWorkConditionConfigForm.spliceCondition.selected" :options="netWorkConditionConfigForm.spliceCondition.options" />
              </td>
            </tr>
            <tr>
              <td class="th">逻辑关系：</td>
              <td>
                <b-form-select size="sm" v-model="netWorkConditionConfigForm.logicalRelation.selected" :options="netWorkConditionConfigForm.logicalRelation.options" />
              </td>
            </tr>
            <tr>
              <td class="th">判断参数：</td>
              <td>
                <b-form-select size="sm" v-model="netWorkConditionConfigForm.judgeParam.selected" :options="netWorkConditionConfigForm.judgeParam.options" />
              </td>
            </tr>
            <tr>
              <td class="th">对比条件：</td>
              <b-form-select size="sm" v-model="netWorkConditionConfigForm.contrastCondition.selected" :options="netWorkConditionConfigForm.contrastCondition.options" />
              <td>
              </td>
            </tr>
            <tr>
              <td class="th">对比值：</td>
              <td>
                <div>
                  <span>
                    <b-form-select size="sm" style="width:160px;" v-model="netWorkConditionConfigForm.contrastValue.selected" :options="netWorkConditionConfigForm.contrastValue.options" />
                  </span>
                </div>
              </td>
            </tr>
            <tr>
              <td class="th"></td>
              <td>
                <div>
                  <b-form-input type="text" v-model="netWorkConditionConfigForm.contrastValue.value" size="sm" style="width:160px" />
                </div>
              </td>
            </tr>
          </table>
        </div>
        <div class="form_btn_div">
          <b-button size="sm" variant="success" @click="addCondition()" style="margin:2.5px;">添加</b-button>
          <b-button size="sm" variant="success" style="margin:2.5px;">重置</b-button>
        </div>
      </b-form>

      <!-- 网元能力分支配置 -->
      <b-form class="pform" ref="NetWorkBranchConfigForm" id="network_branch_config_form" style="float: right; width:400px;" v-show="netWorkBranchConfigForm.show">
        <div class="form_title">网元能力分支配置</div>
        <div class="form_content">
          <table>
            <tr>
              <td class="th">条件：</td>
              <td>
                <b-form-select size="sm" @change="onNetWorkBranConfigFormSelectedChange" v-model="netWorkBranchConfigForm.selected" :options="netWorkBranchConfigForm.options" />
              </td>
            </tr>
          </table>
        </div>
        <div class="form_btn_div">
        </div>
      </b-form>
      <!-- 预处理模型操作 -->
      <form class="pform" ref="PreModelOperationForm" id="pre_model_operation_form" style="float: right; width:400px;">
        <div class="form_title">预处理模型操作</div>
        <div class="form_content">
          <b-button size="sm" @click="$refs.ModelOperationModal.show()" variant="success" style="width: 90%;margin-left: 5%;margin-top: 10px"> 保存模型</b-button>
        </div>
        <div class="form_btn_div">
        </div>
      </form>
    </b-form-group>
    <!-- Modal:预处理模型操作 -->
    <b-modal ref="ModelOperationModal" @ok="modelOperationModalHandleOk" @shown="modelOperationModalShow" @cancel="modelOperationModalClearParam" title="发布模型" size="lg">
      <b-container>
        <form @submit.stop.prevent="modelOperationModalHandleSubmit">
          <b-row class="my-1" style="text-align: left;">
            <b-col sm="2">
              <label v-if="modelOperationModal.selected==2" for="input-none">分支名称</label>
              <label v-else for="input-none">模型名称</label>
            </b-col>
            <b-col sm="10">
              <b-form-input type="text" v-model="modelOperationModal.name" placeholder="模型名称"></b-form-input>
            </b-col>
          </b-row>
          <b-row class="my-1" style="text-align: left;">
            <b-col sm="2">
              <label v-if="modelOperationModal.selected==2" for="input-none">分支描述</label>
              <label v-else for="input-none">模型描述</label>
            </b-col>
            <b-col sm="10">
              <b-form-textarea v-model="modelOperationModal.description" placeholder="模型描述" :rows="3" :max-rows="6">
              </b-form-textarea>
            </b-col>
          </b-row>
          <b-row class="my-1" v-if="modelOperationModal.selected==3" style="text-align: left;">
            <b-col sm="2">
              <label for="input-none">标记</label>
            </b-col>
            <b-col sm="10">
              <b-form-textarea v-model="modelOperationModal.comment" placeholder="记录描述" :rows="3" :max-rows="6">
              </b-form-textarea>
            </b-col>
          </b-row>
          <b-row class="my-1" v-if="modelOperationModal.status=='operation'">
            <b-col sm="12" style="text-align: left;">
              <b-form-group label="保存操作">
                <b-form-radio-group id="radios1" v-model="modelOperationModal.selected" :options="modelOperationModal.options" name="radioOpenions">
                </b-form-radio-group>
              </b-form-group>
            </b-col>
          </b-row>
        </form>
      </b-container>
    </b-modal>

    <!-- Modal:添加网元能力 -->
    <b-modal ref="AddNetWorkModal" title="网元" size="lg">
      <b-container fluid>
        <InfoTable ref="NetWorkTable" location="workings" href="network" :filterFields="addNetWorkModal.filterFields">
          <template slot="button-operation">
            <div></div>
          </template>
          <template slot="table-operation" slot-scope="row">
            <b-btn variant="outline-primary" style="margin-right:8px;padding:6px;font-size:0.7rem" @click="netWorkModalInfo(row.data)">查询信息</b-btn>
            <b-btn variant="outline-primary" style="margin:2px;padding:5px;font-size:0.7rem" @click="addNodeByRow(row.data.item)">添加模型</b-btn>
          </template>
          <template slot="table-bigkind" slot-scope="row">
            {{row.data.item.bigkind | bigkind}}
          </template>
        </InfoTable>
      </b-container>
      <div slot="modal-footer" class="w-100">
        <b-btn size="sm" class="float-right" variant="primary" @click="$refs.AddNetWorkModal.hide()">
          返回
        </b-btn>
      </div>
    </b-modal>
    <!-- Modal:初始化参数 -->
    <b-modal ref="InitParamConfigModal" title="修改参数" size="lg">
      <b-container fluid>
        <div>
          <label for="input-small" style="float:left;margin-right:10px">{{initParamConfigModal.name}}</label>
          <b-form-input type="text" v-model="initParamConfigModal.newValue" size="sm" style="width:160px" />
        </div>
      </b-container>
      <div slot="modal-footer" class="w-100">
        <b-btn size="sm" class="float-right" variant="primary" @click="$refs.InitParamConfigModal.hide()">
          返回
        </b-btn>
        <b-btn size="sm" class="float-right" variant="primary" @click="saveInitParam()">
          保存
        </b-btn>
      </div>
    </b-modal>
    <!-- 用来查看网元能力的详细信息 -->
    <b-modal ref="NetWorkModal" ok-only title="网元能力" size="lg">
      <NetWorkInfoModal v-bind:item="netWorkInfoModalItem"></NetWorkInfoModal>
      <div slot="modal-footer" class="w-100">
        <b-btn size="sm" class="float-right" variant="primary" @click="$refs.NetWorkModal.hide(),$refs.AddNetWorkModal.show()">
          返回
        </b-btn>
      </div>
    </b-modal>
  </div>
</template>
<script>
import InfoTable from "components/InfoTable";
import NetWorkInfoModal from "components/NetWorkInfoModal.vue";
import {
  axios,
  baseURL,
  get,
  save,
  associate,
  getAndAssociate,
  remove,
  update,
  associateByPut
} from "src/service/api";
import { alter } from "src/utils/request";
// 由于Gooflow是jquery插件,所以导入jquery
import $ from "jquery";
import _ from "lodash";
// 导入GooFlow流程图的css
import "assets/css/GooFlow/common.css";
// 导入GooFlow相关函数
import "utils/Gooflow/index";
// 故障预处理模型管理主要是对模型的新增、删除、修改和查询,这是画图界面
export default {
  name: "FaultAnticipateModelManager",
  components: {
    NetWorkInfoModal,
    InfoTable
  },
  filters: {
    bigkind: function(value) {
      switch (value) {
        case 1:
          return "传输";
          break;
        case 2:
          return "交换";
          break;
        case 3:
          return "数据";
          break;
        case 4:
          return "其他";
          break;
        case 0:
          return "未归档";
          break;
      }
    }
  },
  data() {
    return {
      isLoadedData: false,
      result: null,
      currentModel: {},
      currentRecord: {},
      currentDetail: {},
      currentBranch: {},
      // 画布,或者说是要用的整个画图对象
      cavans: "",
      x: 0,
      oldtime: new Date().getTime(),
      uploadId: 0,

      changeObj: null,
      //导出结果
      out: null,

      selectList: [],

      winWidth: 1200,
      winHight: 600,
      // 要添加的节点
      nowJson: "",
      // 当前选中的节点
      clientNode: "",
      // 存储节点信息,比如初始化参数配置存这里
      nodeInfo: [],
      // 存储分支,还有线段
      branch: [],
      //存储网元能力条件列表
      conditionList: [
        {
          cavans_node_52: ["flag-9ZOW1 = 1"]
        },
        {},
        {
          tz_node_begin: [
            "sswy-5H2AY 包含 华为",
            "sswy-5H2AY 包含 中兴",
            "sswy-5H2AY 包含 FHAN 或 sswy-5H2AY 包含 FH 且 sswy-5H2AY 包含 AN"
          ]
        }
      ],
      //工具栏提示
      remark: {
        cursor: "选择指针",
        direct: "结点连线",
        task: "关联信息查询结点",
        node: "网元能力结点",
        fork: "判断分支结点"
      },
      netWorkInfoModalItem: {
        description: "1",
        id: "1",
        in: [],
        name: "1",
        out: []
      },
      // Model:属性设置
      currentSelectedModel: {
        id: "未选择",
        name: "未选择"
      },
      // Model:故障预处理模型
      modelOperationModal: {
        status: "create",
        name: "",
        description: "",
        selected: 1,
        comment: "",
        options: [
          { text: "覆盖", value: 1 },
          { text: "新建分支", value: 2 },
          { text: "副本", value: 3 }
        ]
      },
      // Model:初始化参数
      initParamConfigModal: {
        name: "",
        value: "",
        newValue: ""
      },
      // Model:初始化配置参数
      initParamConfigForm: {
        show: false,
        fields: [
          {
            key: "order",
            label: "主键"
          },
          {
            key: "value",
            label: "参数名"
          },
          {
            key: "type",
            label: "参数定值"
          },
          {
            key: "operation",
            label: "操作"
          }
        ],
        count: 0,
        hasSpace: true,
        value: "",
        type: "",
        store: []
      },

      // Form:网元能力入参配置
      networkInputParamConfigForm: {
        show: false,
        store: [
          {
            namelistauto: "",
            vallistauto: "",
            key: "",
            select: {
              selected: null,
              options: []
            },
            wleng: -1
          }
        ]
      },
      // Form:网元能力条件
      netWorkConditionForm: {
        show: false,
        store: [
          {
            key: "1",
            text: "13"
          }
        ]
      },
      // Form:网元能力条件配置
      netWorkConditionConfigForm: {
        show: false,
        // 拼接条件
        spliceCondition: {
          selected: null,
          options: [{ value: null, text: "Please select an option" }]
        },
        // 逻辑关系
        logicalRelation: {
          selected: null,
          options: [
            { value: "且", text: "且运算" },
            { value: "或", text: "或运算" }
          ]
        },
        // 判断参数
        judgeParam: {
          selected: null,
          options: []
        },
        // 对比条件
        contrastCondition: {
          selected: null,
          options: [
            { value: "1", text: "大于(>)" },
            { value: "2", text: "小于(<)" },
            { value: "3", text: "等于(=)" },
            { value: "4", text: "大于等于(>=)" },
            { value: "5", text: "小于等于(<=)" },
            { value: "6", text: "包含有" },
            { value: "7", text: "正则表达式" }
          ]
        },
        // 对比值
        contrastValue: {
          selected: null,
          options: [],
          value: ""
        }
      },
      //Form:网元能力分支配置
      netWorkBranchConfigForm: {
        show: false,
        selected: null,
        options: []
      },
      addNetWorkModal: {
        filterFields: ["bigkind"]
      }
    };
  },
  mounted: async function() {
    let self = this;
    let result = null;
    let entry = null;
    let isMasterBranch = null;
    if (this.$route.query.entry != null) {
      entry = JSON.parse(this.$route.query.entry);
      isMasterBranch = JSON.parse(this.$route.query.isMasterBranch);
    }
    if (entry != null) {
      if (isMasterBranch) {
        this.currentDetail = entry;
        console.log("传递的是主分支数据");
        console.log(this.currentDetail);
        await this.getCurrentModelByMasterBranch(this.currentDetail).then(
          reponse => {
            console.log(reponse);
            result = reponse;
          }
        );
      } else {
        this.currentRecord = entry;
        console.log("传递的根据模型历史数据");
        console.log(this.currentRecord);
        await this.getCurrentModelByModel(this.currentRecord).then(reponse => {
          console.log(reponse);
          result = reponse;
        });
      }
      console.log("当前得到的模型是:");
      console.log(result);
      self.conditionList = JSON.parse(result.condition);
      self.nodeInfo.push({
        tz_node_begin: {
          out: JSON.parse(result.initParam)
        }
      });
      //表示 tz_node_begin已经存在了
      self.initParamConfigForm.hasSpace = false;
      let wleng = 0;
      // 添加初始化条件
      for (let pq = 0; pq < this.nodeInfo.length; pq++) {
        $.each(this.nodeInfo[pq], function(name, value) {
          if (name == "tz_node_begin") {
            console.log(value["out"]);
            $.each(value["out"], function(key, val) {
              console.log(val);
              let newVal = val.substring(2, val.length);
              // 将入参的数据传入右边初始化入参列表
              self.initParamConfigForm.store.push({
                order: self.initParamConfigForm.count + 1,
                value: key,
                type: newVal
              });
              self.initParamConfigForm.count++;
            });
          }
        });
      }
      // 导入数据
      self.cavans.loadData(JSON.parse(result.content));

      self.branch = JSON.parse(result.branch);

      self.selectList = JSON.parse(result.select);

      self.modelOperationModal.name = self.currentDetail.name;

      self.modelOperationModal.description = self.currentDetail.description;

      self.modelOperationModal.status = "operation";
    }
    //数据加载完毕
    this.isLoadedData = true;
  },
  // 挂载之后,初始化画布,为画图添加操作事件
  created() {
    let self = this;
    $(document).ready(function() {
      get("wynl/model")
        .then(response => {
          if (response.data == "") {
            self.nodeInfo = [];
          }
        })
        .catch(error => {
          console.log(error);
        });
      // 定义画图宽度
      self.winWidth = document.body.clientWidth - 440;
      // 定义画图高度
      self.winHight = document.documentElement.clientHeight;
      /*
        property : 定义工具栏、编辑器相关属性;
        remark   : 定义工具栏提示;
      */
      // 配置工具栏等工具
      let property = {
        width: self.winWidth,
        height: self.winHight,
        toolBtns: ["node"],
        haveHead: false,
        haveTool: true,
        haveGroup: true,
        useOperStack: true
      };
      // 默认状态
      // 自动提交故障预处理模型
      // 更新时间

      // 绑定HTML元素,并配置参数
      self.cavans = $.createGooFlow($("#cavans"), property);
      // 配置工具栏
      self.cavans.setNodeRemarks(self.remark);
      // 删除
      self.cavans.onItemDel = (id, type) => {
        if (confirm("确定要删除该单元吗??")) {
          //调用GooFlow自身的方法
          self.cavans.blurItem();
          return true;
        } else {
          return false;
        }
      };
      // 重命名(不知道为什么没反应)
      self.cavans.onItemRename = (id, name, type) => {
        console.log("name:" + name);
      };
      // 添加
      self.cavans.onItemAdd = (id, type, json) => {
        // 判断添加的元素
        switch (type) {
          case "node":
            if (self.x >= 3 && self.isLoadedData) {
              // 显示要添加的Modal，用于获取要加入的网元
              self.$refs.AddNetWorkModal.show();
              // 加载数据
              self.loadNetWorkModalTableData();
              console.log("显示json");
              console.log(json);
              // 因为默认添加的node的开头名是node,所以判断添加的Node节点是否是网元
              if (json.name.indexOf("node") != 0) {
                return true;
              } else {
                self.nowjson = json;
                return false;
              }
            } else {
              self.x++;
              return true;
            }
            break;
          case "line":
            // 防止自循环
            if (json.from == json.to) return;
            let tp = {};
            tp[id] = "default";
            // 添加线段
            self.branch.push(tp);
            return true;
            break;
        }
      };
      // 判断是否是修改
      if (self.$route.query.entry == null) {
        // 初始导入数据
        self.cavans.loadData({
          title: "故障预处理模型",
          nodes: {
            tz_node_begin: {
              name: "故障处理开始",
              left: 100,
              top: 58,
              type: "start round",
              width: 24,
              height: 24,
              alt: true
            },
            tz_node_end: {
              name: "故障正常结束",
              left: 100,
              top: 400,
              type: "end round",
              width: 24,
              height: 24,
              alt: true
            },
            tz_node_error: {
              name: "故障异常结束",
              left: 300,
              top: 400,
              type: "end round",
              width: 24,
              height: 24,
              alt: true
            }
          },
          lines: {},
          areas: {},
          initNum: 52
        });
      }
      // 当操作某个单元（结点/线）被由不选中变成选中时，触发的方法
      self.cavans.onItemFocus = (id, model) => {
        console.log("id:" + id);
        // 声明一个对象,获取信息用
        let o;
        // 属性设置中的名称设置为被选中的模型的id(差不多唯一标识符之类的)
        self.currentSelectedModel.id = id;
        // 如果被选中的是线
        if (model == "line") {
          console.log("line");
          // 根据id找到对应的线条,然后将属性之类的获取到o中
          o = self.cavans.$lineData[id];
          // 显示在右侧的参数查看区
          self.showLine(o.from);
          // 如果被选中的是节点
        } else if (model == "node") {
          console.log(self.cavans.$nodeData[id]);
          o = self.cavans.$nodeData[id];
          // 当前选中的节点
          self.clientNode = o;
          // 如果选中的节点是开始端,则只用显示初始化参数From就可以了
          if (o.type == "start round") {
            // initParamConfigForm显示
            self.initParamConfigForm.show = true;
            // 只要不等于结束端
          } else if (o.type != "end round") {
            console.log("节点被选中了");
            //显示在右侧的参数查看区
            self.showNode(id);
            // 获取所有参数属性-------
            let wleng = self.getParentNodeAllAttr(id);
            self.reback(wleng); //显示已选择参数
          }
        }
        self.currentSelectedModel.name = o.name;
        return true;
      };
      // 当操作某个单元（结点/线）被由选中变成不选中时，触发的方法
      self.cavans.onItemBlur = (id, model) => {
        // 初始化配置
        self.currentSelectedModel.id = "未选择";
        self.currentSelectedModel.name = "未选择";
        console.log("id:" + id);
        // 回到初始状态
        self.setNomalStatus();
        return true;
      };
    });
  },
  methods: {
    loadNetWorkModalTableData() {
      let self = this;
      get(
        "workings?size=" +
          this.addNetWorkModal.perPage +
          "&page=" +
          (this.addNetWorkModal.currentPage - 1)
      )
        .then(function(response) {
          if (response.status == "200") {
            console.log("资源获取成功");
            self.addNetWorkModal.items = response.data._embedded.workings;
            self.addNetWorkModal.totalRows = response.data.page.totalElements;
          }
          console.log(response);
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    getrand(n) {
      let chars = [
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z"
      ];

      let res = "";
      for (var i = 0; i < n; i++) {
        var id = Math.ceil(Math.random() * 35);
        res += chars[id];
      }
      return res;
    },
    getStringLength(str) {
      if (str == null) return 0;
      if (typeof str != "string") {
        str += "";
      }
      return str.replace(/[^\x00-\xff]/g, "01").length;
    },
    getIdByPath(str) {
      return str.substring(baseURL, str.length);
    },
    //Method:modelOperationModalClearParam 上传模型
    modelOperationModalShow() {
      if (this.currentDetail.name) {
        this.modelOperationModal.name = this.currentDetail.name;
        this.modelOperationModal.description = this.currentDetail.description;
      }
    },
    //Method:modelOperationModalClearParam 上传模型
    modelOperationModalClearParam() {
      // this.modelOperationModal.name = "";
      // this.modelOperationModal.selected = null;
      // this.modelOperationModal.description = "";
    },
    modelOperationModalHandleOk(evt) {
      // Prevent modal from closing
      evt.preventDefault();
      if (!this.modelOperationModal.name) {
        alert("请输入名称");
      } else {
        this.modelOperationModalHandleSubmit();
      }
    },
    newModelSave() {
      let self = this;
      let name = this.modelOperationModal.name;
      let description = this.modelOperationModal.description;
      let initParamData = this.setInitParamData();
      if (this.uploadId == 0) {
        this.uploadData(name, description, initParamData);
      }
    },
    setInitParamData() {
      let initParamData;
      for (let pq = 0; pq < this.nodeInfo.length; pq++) {
        $.each(this.nodeInfo[pq], function(name, value) {
          if (name == "tz_node_begin") {
            $.each(value, function(inname, invalue) {
              console.log(inname);
              initParamData = invalue;
            });
          }
        });
      }
      return initParamData;
    },
    newModelUpdateByBranch: async function() {
      let model;
      let branch;
      let branchId;
      let name = this.modelOperationModal.name;
      let description = this.modelOperationModal.description;
      let initParamData = this.setInitParamData();
      await save("models", {
        initParam: JSON.stringify(initParamData),
        content: JSON.stringify(this.cavans.exportData()),
        condition: JSON.stringify(this.conditionList),
        branch: JSON.stringify(this.branch),
        select: JSON.stringify(this.selectList)
      })
        .then(response => {
          if (response.status == "201") {
            model = response.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
      await save("details/manager/update/branch", {
        detail: {
          id: this.getKey(this.currentDetail._links.self.href)
        },
        model: {
          id: this.getKey(model._links.self.href)
        },
        branch: {
          name: name,
          description: description,
          isMaster: false
        },
        lastBranch: {
          id: this.getKey(this.currentBranch._links.self.href)
        }
      })
        .then(response => {
          if (response.status == "200") {
            branchId = response.data;
            alert("新建分支成功");
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    newModelUpdateByCopy: async function() {
      let model;
      let recordId;
      let name = this.modelOperationModal.name;
      let description = this.modelOperationModal.description;
      let comment = this.modelOperationModal.comment;
      let initParamData = this.setInitParamData();
      await save("models", {
        initParam: JSON.stringify(initParamData),
        content: JSON.stringify(this.cavans.exportData()),
        condition: JSON.stringify(this.conditionList),
        branch: JSON.stringify(this.branch),
        select: JSON.stringify(this.selectList)
      })
        .then(response => {
          if (response.status == "201") {
            model = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      await save("details/manager/update/copy", {
        record: {
          modelId: this.getKey(model._links.self.href),
          comment: comment
        },
        currentBranch: {
          id: this.getKey(this.currentBranch._links.self.href)
        }
      })
        .then(response => {
          if (response.status == "200") {
            recordId = response.data;
            alert("新建副本成功");
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
    },
    newModelUpdateByCover: async function() {
      let self = this;
      let name = this.modelOperationModal.name;
      let description = this.modelOperationModal.description;
      let initParamData = this.setInitParamData();
      console.log(initParamData);
      // 更新模型
      await update(this.currentModel._links.self.href, {
        initParam: JSON.stringify(initParamData),
        content: JSON.stringify(self.cavans.exportData()),
        condition: JSON.stringify(self.conditionList),
        branch: JSON.stringify(self.branch),
        select: JSON.stringify(self.selectList)
      }).then(reponse => {
        if (reponse.status == "200") {
          console.log("资源修改成功");
        }
        console.log(reponse);
      });
      // 更新名称
      await update(this.currentDetail._links.self.href, {
        name: name,
        description: description
      }).then(reponse => {
        if (reponse.status == "200") {
          console.log("资源修改成功");
          alert("保存成功");
        }
        console.log(reponse);
      });
    },
    newModelUpdate: async function() {
      switch (this.modelOperationModal.selected) {
        case 1:
          this.newModelUpdateByCover();
          break;
        case 2:
          this.newModelUpdateByBranch();
          break;
        case 3:
          this.newModelUpdateByCopy();
          break;
      }
      console.log("保存");
    },
    modelOperationModalHandleSubmit() {
      if (this.modelOperationModal.status == "create") {
        this.newModelSave();
      } else if (this.modelOperationModal.status == "operation") {
        this.newModelUpdate();
      }
      this.modelOperationModalClearParam();
      this.$refs.ModelOperationModal.hide();
    },
    getKey(str) {
      let position = str.lastIndexOf("/");
      return str.substring(position + 1, str.length);
    },
    getCurrentModelByModel: async function(currentRecord) {
      let self = this;
      let model;
      let detail;
      let key = parseInt(this.getKey(currentRecord._links.self.href));
      let branch;
      // 获取branch
      await get(currentRecord._links.branch.href)
        .then(response => {
          if (response.status == "200") {
            console.log("资源branch获取成功");
            branch = response.data;
            this.currentBranch = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      // 获取detail
      await get(branch._links.detail.href)
        .then(response => {
          if (response.status == "200") {
            console.log("资源detail获取成功");
            detail = response.data;
            this.currentDetail = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      // 获取records下的Model
      await get(`models/${currentRecord.modelId}`)
        .then(response => {
          if (response.status == "200") {
            console.log("资源model获取成功");
            model = response.data;
            this.currentModel = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      return model;
    },
    getCurrentModelByMasterBranch: async function(currentRecord) {
      let self = this;
      let model;
      let detail;
      let record;
      let key = parseInt(this.getKey(currentRecord._links.self.href));
      let lastMaster;
      // 获取master
      await get(`branches/search/detail?detailId=${key}&isMaster=true`)
        .then(response => {
          if (response.status == "200") {
            console.log("资源branch获取成功");
            lastMaster = response.data._embedded.branches[0];
            this.currentBranch = response.data._embedded.branches[0];
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      // 根据master下的最新时间获取record
      await get(
        `records/search/lately?branchId=${this.getKey(
          lastMaster._links.self.href
        )}`
      )
        .then(response => {
          if (response.status == "200") {
            console.log("资源record获取成功");
            record = response.data;
            this.currentRecord = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      // 获取records下的Model
      await get(`models/${record.modelId}`)
        .then(response => {
          if (response.status == "200") {
            console.log("资源model获取成功");
            model = response.data;
            this.currentModel = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      console.log("预处理模型的model:");
      console.log(model);
      return model;
    },
    uploadDataTest() {
      getAndAssociate("details/13", "records", false);
      associateByPut("records/4/detail", "details/12");
      save("models", {
        initParam: JSON.stringify(initParamData),
        content: JSON.stringify(this.cavans.exportData()),
        condition: JSON.stringify(this.conditionList),
        branch: JSON.stringify(this.branch),
        select: JSON.stringify(this.selectList)
      });
    },
    uploadData: async function(name, description, initParamData) {
      console.log(name);
      console.log("保存");
      let self = this;
      let model;
      let detailId;
      await save("models", {
        initParam: JSON.stringify(initParamData),
        content: JSON.stringify(self.cavans.exportData()),
        condition: JSON.stringify(self.conditionList),
        branch: JSON.stringify(self.branch),
        select: JSON.stringify(self.selectList)
      })
        .then(response => {
          if ((response.status = "201")) {
            model = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      await save("details/manager/save", {
        model: {
          id: this.getKey(model._links.self.href)
        },
        detail: {
          name: name,
          description: description
        },
        branch: {
          name: name,
          description: description,
          isMaster: true
        }
      })
        .then(response => {
          if ((response.status = "200")) {
            detailId = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      await associateByPut(`details/${detailId}/teams`, "teams/1")
        .then(response => {
          if ((response.status = "200")) {
            alert("发布成功");
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
    },
    getHref(Record, name) {
      return Record._links[name].href;
    },
    //取得所有网元信息,进行比较获取当前的网元信息,然后将入参配置到右边的入参列表中
    getParentNodeAllAttr(begin) {
      console.log("取得所有父节点参数");
      let self = this;
      //判断参数 清空数据
      this.netWorkConditionConfigForm.judgeParam.options = [];
      //网元能力入参 界面清空
      //$("#branchview").empty();
      this.networkInputParamConfigForm.store = [];
      // 对比值 select 清空数据
      this.netWorkConditionConfigForm.contrastValue.options = [];
      // 对比值 input数据清空
      this.netWorkConditionConfigForm.contrastValue.value = "";

      let stack = []; //防止重复循环

      let wleng = 0;

      // 网元入参配置,还没成功
      for (let i = 0; i < this.nodeInfo.length; i++) {
        // nodeInfo[0]是所有网元
        // nodeInfo[1]是初始化入参列表
        $.each(this.nodeInfo[i], (name, value) => {
          console.log("init:" + name + "|" + begin);
          console.log(
            "name:" + name + "  begin.split(' - ')[0]:" + begin.split("-")[0]
          );
          // 目的是匹配所有网元,然后找到aim节点网元
          if (name == begin.split("-")[0]) {
            console.log("找到了一个:" + name);
            console.log(this.nodeInfo[i][name]);
            let final = "-" + begin.split("-")[1];
            // 对网元的入参进行遍历
            $.each(value.in, function(key, val) {
              console.log("");
              // 将入参的数据传入右边初始化入参列表
              self.networkInputParamConfigForm.store.push({
                namelistauto: key,
                key: i,
                vallistauto: wleng,
                select: {
                  selected: null,
                  options: []
                },
                wleng: wleng
              });
              // 条件判断
              // 将入参的数据添加到 判断参数列表
              self.netWorkConditionConfigForm.judgeParam.options.push({
                value: key + final,
                text: key + final
              });
              // 将入参的数据添加到 对比值列表
              self.netWorkConditionConfigForm.contrastValue.options.push({
                value: key + final,
                text: key + final
              });
              wleng++;
            });
          }
        });
      }
      this.getParentNodeAttr(begin, stack, wleng);
      return wleng;
    },
    // 判断节点的连线情况
    getParentNodeAttr(aim, stacks, wleng) {
      console.log("wleng:" + wleng);
      console.log("stacks:" + stacks);
      console.log("aim:一般表示的被选中的这个节点的Id");
      console.log("aim:" + aim);
      let end = [];
      let self = this;
      console.log("判断节点的连线情况:遍历线列表");
      for (let x in this.cavans.$lineDom) {
        // 根据id,和要获取的数据类型type(有”node”,”line”,”area”三种取值),返回相应的结点json数据单元
        console.log(
          'this.cavans.getItemInfo(x, "line").to:表示的是线列表中目标节点'
        );
        console.log(
          'this.cavans.getItemInfo(x, "line").to:' +
            this.cavans.getItemInfo(x, "line").to
        );
        // 有线段指向这个节点的时候
        if (this.cavans.getItemInfo(x, "line").to == aim) {
          // 声明一个判断变量
          let flag = true;
          // 查找stacks数组中的元素是否是和cavans.getItemInfo(x, "line").from一样的元素
          for (let i = 0; i < stacks.length; i++) {
            if (stacks[i] == this.cavans.getItemInfo(x, "line").from) {
              console.log(
                "这里是Y:" +
                  stacks[i] +
                  "|这里是from:" +
                  this.cavans.getItemInfo(x, "line").from
              );
              flag = false;
              break;
            }
          }
          // 如果没有的话,就将cavans.getItemInfo(x, "line").from放入end数组中
          if (flag) {
            end.push(this.cavans.getItemInfo(x, "line").from);
          }
        }
      }
      console.log("end[i]:" + end);
      console.log("stacks[i]:" + stacks);
      // 遍历end数组
      for (let i = 0; i < end.length; i++) {
        // 先将end的元素存入stacks中
        stacks.push(end[i]);
        // 如果指向这个节点的那个节点不是开始节点
        if (end[i] != "tz_node_begin") {
          for (let j = 0; j < this.nodeInfo.length; j++) {
            $.each(this.nodeInfo[j], (name, value) => {
              // 目的是匹配所有网元,然后找到指向这个aim节点的那个节点的出参信息
              if (name == end[i].split("-")[0]) {
                let final = "-" + end[i].split("-")[1];
                //将所有出参信息都加入到右边初始化入参列表
                $.each(value.out, (key, val) => {
                  //判断参数 添加选择
                  self.netWorkConditionConfigForm.judgeParam.options.push({
                    value: key + final,
                    text: key + final
                  });
                  self.netWorkConditionConfigForm.contrastCondition.options.push(
                    {
                      value: key + final,
                      text: key + final
                    }
                  );
                  for (let z = 0; z < wleng; z++) {
                    self.networkInputParamConfigForm.store[
                      z
                    ].select.options.push({
                      value: key + final,
                      text: key + final
                    });
                  }
                });
              }
            });
          }
        } else {
          for (let j = 0; j < this.nodeInfo.length; j++) {
            $.each(this.nodeInfo[j], (name, value) => {
              //console.log('init:'+name+"|"+end.split('-')[0]);
              if (name == end[i]) {
                let final = "-Origin";
                $.each(value.out, (key, val) => {
                  //判断参数 添加选择
                  self.netWorkConditionConfigForm.judgeParam.options.push({
                    value: key + final,
                    text: key + final
                  });
                  self.netWorkConditionConfigForm.contrastCondition.options.push(
                    {
                      value: key + final,
                      text: key + final
                    }
                  );
                  //本节点网元能力入参  添加选择
                  for (var z = 0; z < wleng; z++) {
                    self.networkInputParamConfigForm.store[
                      z
                    ].select.options.push({
                      value: key + final,
                      text: key + final
                    });
                  }
                });
              }
            });
          }
        }
        this.getParentNodeAttr(end[i], stacks, wleng);
      }
    },
    //回滚
    reback(wleng) {
      console.log(wleng);
      for (let i = 0; i < this.selectList.length; i++) {
        let tp = this.selectList[i].split("&");
        if (tp[0] == this.currentSelectedModel.id) {
          for (let j = 0; j < wleng; j++) {
            if (
              this.networkInputParamConfigForm.store[j].namelistauto.length > 0
            ) {
              console.log(
                "namelistauto:" +
                  this.networkInputParamConfigForm.store[j].namelistauto
              );
              console.log(
                "tp[1]:" +
                  this.networkInputParamConfigForm.store[j].namelistauto
              );
              if (
                this.networkInputParamConfigForm.store[j].namelistauto == tp[1]
              ) {
                this.networkInputParamConfigForm.store[j].select.selected =
                  tp[2];
              }
            } else {
              break;
            }
          }
        }
      }
    },
    //显示线节点数据
    showLine(id) {
      let self = this;
      //首先要把所有不相关的表单隐藏
      this.netWorkConditionForm.show = false;
      this.networkInputParamConfigForm.show = false;
      this.netWorkConditionConfigForm.show = false;
      this.initParamConfigForm.show = false;
      this.netWorkBranchConfigForm.show = true;
      // 添加
      this.netWorkBranchConfigForm.options = [];
      this.netWorkBranchConfigForm.options.push({
        value: "default",
        text: "默认分支"
      });
      // 显示网元能力分支列表 从conditionList中获取
      for (let i = 0; i < this.conditionList.length; i++) {
        _.forEach(this.conditionList[i], function(name, value) {
          console.log(value);
          console.log(id);
          if (value == id) {
            for (let y = 0; y < name.length; y++) {
              self.netWorkBranchConfigForm.options.push({
                value: name[y],
                text: y + 1 + ":" + name[y]
              });
              // 显示当前节点选中了那个分支
              for (let j = 0; j < self.branch.length; j++) {
                _.forEach(self.branch[j], function(name, value) {
                  if (value == self.currentSelectedModel.id) {
                    self.netWorkBranchConfigForm.selected =
                      self.branch[j][self.currentSelectedModel.id];
                  }
                });
              }
            }
          }
        });
      }
    },
    //显示普通节点数据
    showNode(id) {
      console.log("显示普通节点数据");
      console.log("被选中的节点的id" + id);
      let self = this;
      //首先要把所有不相关的表单隐藏
      this.netWorkBranchConfigForm.show = false;
      this.initParamConfigForm.show = false;
      this.netWorkConditionConfigForm.show = true;
      this.networkInputParamConfigForm.show = true;
      this.netWorkConditionForm.show = true;
      //$("#conditionview").empty();
      this.netWorkConditionForm.store = [];
      this.netWorkConditionConfigForm.spliceCondition.options = [];
      this.netWorkConditionConfigForm.spliceCondition.options.push({
        value: "new",
        text: "新条件"
      });
      for (let i = 0; i < this.conditionList.length; i++) {
        $.each(this.conditionList[i], function(name, value) {
          if (name == id) {
            for (let y = 0; y < value.length; y++) {
              /* $("#conditionview").append(
                '<tr><td class="th">' +
                  (y + 1) +
                  ":</td><td>" +
                  value[y] +
                  '</td><td onclick="showNodeDel(this)" style="color: red">&nbsp;删除</td></tr>'
              );
              */
              self.netWorkConditionForm.store.push({
                key: y + 1,
                text: value[y]
              });
              self.netWorkConditionConfigForm.spliceCondition.options.push({
                value: value[y],
                text: y + 1 + ":" + value[y]
              });
            }
          }
        });
      }
    },
    //将所有状态进行初始化,显示普通状态
    setNomalStatus() {
      //网元能力分支配置
      this.netWorkBranchConfigForm.show = false;
      // 网元能力条件配置
      this.netWorkConditionConfigForm.show = false;
      // 网元能力条件
      this.netWorkConditionForm.show = false;
      // 初始参数配置
      this.initParamConfigForm.show = false;
      // 网元能力入参配置
      this.networkInputParamConfigForm.show = false;
    },
    //网元能力分支配置条件分支条件监听,一般是线上的操作
    onNetWorkBranConfigFormSelectedChange(value) {
      console.log(value);
      this.netWorkBranchConfigForm.selected = value;
      let self = this;
      let flagin = true;
      for (let i = 0; i < this.branch.length; i++) {
        _.forEach(this.branch[i], (name, vlaue) => {
          if (value == self.currentSelectedModel.id) {
            self.branch[i][self.currentSelectedModel.id] =
              self.netWorkBranchConfigForm.selected;
            flagin = false;
          }
        });
      }

      if (flagin) {
        let tp = {};
        // 不太确定是被选中的value还是text
        tp[self.currentSelectedModel.id] =
          self.netWorkBranchConfigForm.selected;
        self.branch.push(tp);
      }
    },
    //添加节点
    addNode(id, name) {
      console.log("添加：" + id);
      id = id + "-" + this.getrand(5);
      this.nowjson.name = name;
      this.nowjson.id = id;
      this.cavans.addNode(id, this.nowjson);
    },
    netWorkModalInfo(entry) {
      let self = this;
      get("wynl/list/" + entry.item.code)
        .then(response => {
          if (response.status == "200") {
            console.log("资源获取成功");
            self.netWorkInfoModalItem = response.data;
          }
          console.log(response);
        })
        .catch(error => {
          console.log(error);
        });
      self.$refs.NetWorkModal.show();
    },
    //添加节点
    addNodeByRow(item) {
      console.log(item);
      // nodejs是指向
      let code = item.code + "-" + this.getrand(5);
      this.nowjson.name = item.name;
      this.nowjson.id = code;
      this.cavans.addNode(code, this.nowjson);
      alert("添加成功");
      this.$refs.AddNetWorkModal.hide();
    },
    //上传模型(保存)
    uploadModel() {},
    // 自动上传(保存)模型
    autoUploadModelTask() {},
    exportModel() {
      // 将导出的json对象
      let out = JSON.stringify(this.cavans.exportData());
      // 结果存入result;
      document.getElementById("result").value = out;
    },
    //添加条件
    addCondition() {
      let self = this;
      let rvalue = this.buildCondition();
      // 是否是新条件
      let isNewCondition = true;
      if (rvalue == null) {
        alert("请设置有效条件");
        return;
      }
      // 判断添加的条件是否是新条件,如果不是,isNewCondition=false
      if (this.netWorkConditionConfigForm.spliceCondition.selected != "new") {
        isNewCondition = false;
      }
      let flag = true;
      for (let i = 0; i < this.conditionList.length; i++) {
        $.each(this.conditionList[i], function(name, value) {
          // 判断conditionList中是否有当前选中的节点
          if (name == self.clientNode.id) {
            flag = false;
            //如果是新条件
            if (isNewCondition) {
              value.push(rvalue);
              // 刷新当前节点
              self.showNode(self.clientNode.id);
              return;
            } else {
              for (let k = 0; k < value.length; k++) {
                if (
                  value[k] ==
                  self.netWorkConditionConfigForm.spliceCondition.selected
                ) {
                  // 将旧逻辑和新逻辑合并
                  value[k] =
                    value[k] +
                    " " +
                    self.netWorkConditionConfigForm.logicalRelation.selected +
                    " " +
                    rvalue;
                  // 刷新
                  self.showNode(self.clientNode.id);
                  return;
                }
              }
            }
          }
        });
      }
      if (flag) {
        let tp = [rvalue];
        let map = {};
        map[this.clientNode.id] = tp;
        this.conditionList.push(map);
      }
      this.showNode(this.clientNode.id);
    },
    //取得键入的条件
    buildCondition() {
      if (
        this.netWorkConditionConfigForm.contrastValue.value == null ||
        this.netWorkConditionConfigForm.contrastValue.value == ""
      ) {
        return null;
      } else {
        //新条件
        var str = this.netWorkConditionConfigForm.judgeParam.selected + " ";
        switch (this.netWorkConditionConfigForm.contrastCondition.selected) {
          case "1":
            str += ">";
            break;
          case "2":
            str += "<";
            break;
          case "3":
            str += "=";
            break;
          case "4":
            str += ">=";
            break;
          case "5":
            str += "<=";
            break;
          case "6":
            str += "包含";
            break;
          case "7":
            str += "正则";
            break;
          default:
            str += "=";
        }
        str += " " + this.netWorkConditionConfigForm.contrastValue.value;
        return str;
      }
    },
    //Method: addInitParam 添加初始条件
    addInitParam() {
      let self = this;
      let isAllowInsert = true;
      for (let i = 0; i < this.initParamConfigForm.store.length; i++) {
        if (
          this.initParamConfigForm.store[i].value ==
          this.initParamConfigForm.value
        ) {
          alert("参数名不能重复");
          isAllowInsert = false;
          break;
        }
      }
      if (isAllowInsert) {
        // 将输入数据存入store中
        this.initParamConfigForm.store.push({
          order: this.initParamConfigForm.count + 1,
          value: this.initParamConfigForm.value,
          type: this.initParamConfigForm.type
        });
        // 如果是第一次插入数据
        if (this.initParamConfigForm.hasSpace) {
          let item = {};
          // 如果参数定值有值的话
          if (this.initParamConfigForm.type.length > 0) {
            item[this.initParamConfigForm.value] =
              "&&" + this.initParamConfigForm.type;
          } else {
            item[this.initParamConfigForm.value] = "";
          }
          this.nodeInfo.push({
            tz_node_begin: {
              out: item
            }
          });
          this.initParamConfigForm.hasSpace = false;
        } else {
          for (let pq = 0; pq < this.nodeInfo.length; pq++) {
            _.forEach(this.nodeInfo[pq], function(name, value) {
              if (value == "tz_node_begin") {
                _.forEach(name, function(inname, invalue) {
                  if (self.initParamConfigForm.type.length > 0) {
                    // 这里是输入数据
                    inname[self.initParamConfigForm.value] =
                      "&&" + self.initParamConfigForm.type;
                  } else {
                    inname[self.initParamConfigForm.value] = "";
                  }
                });
              }
            });
          }
        }
        this.initParamConfigForm.count++;
      }
      this.initParamConfigForm.value = "";
      this.initParamConfigForm.type = "";
    },
    // 保存初始条件
    saveInitParam() {
      let self = this;
      let key = null;
      for (let i = 0; i < this.initParamConfigForm.store.length; i++) {
        console.log(this.initParamConfigForm.store[i].type);
        console.log(this.initParamConfigModal.value);
        if (
          this.initParamConfigForm.store[i].type ==
          this.initParamConfigModal.value
        ) {
          this.initParamConfigForm.store[
            i
          ].type = this.initParamConfigModal.newValue;
          key = this.initParamConfigForm.store[i].value;
          for (let pq = 0; pq < this.nodeInfo.length; pq++) {
            $.each(this.nodeInfo[pq], function(name, value) {
              if (name == "tz_node_begin") {
                $.each(value, function(inname, invalue) {
                  console.log(invalue);
                  invalue[key] = "&&" + self.initParamConfigModal.newValue;
                });
              }
            });
          }
          break;
        }
      }
      this.$refs.InitParamConfigModal.hide();
    },
    // 删除初始条件
    deleteInitParam(o) {
      let self = this;
      if (confirm("确定要删除吗？??")) {
        $.each(this.nodeInfo[1]["tz_node_begin"]["out"], function(name, value) {
          console.log(o.value);
          console.log(name);
          if (o.value == name) {
            delete self.nodeInfo[1]["tz_node_begin"]["out"][name];
            for (let i = 0; i < self.initParamConfigForm.store.length; i++) {
              if (self.initParamConfigForm.store[i].value == o.value) {
                self.initParamConfigForm.store.splice(i, 1);
                break;
              }
            }
            return;
          }
        });
        return true;
      } else {
        return false;
      }
    },
    showInitParamConfigFormChangeModal(o) {
      // 在表格中value指的是参数名,type代表参数定值
      // 而在modal中name代表参数名,value代表参数定值
      console.log(o);
      this.$refs.InitParamConfigModal.show();
      this.initParamConfigModal.name = o.value;
      this.initParamConfigModal.value = o.type;
      this.initParamConfigModal.newValue = o.type;
    },
    // 选择节点入参删除
    selectionOriginDel(list, val) {
      for (var i = 0; i < list.length; i++) {
        if (list[i] == null || list[i] == "" || val.length > list[i].length) {
          continue;
        } else if (list[i].substr(0, val.length) == val) {
          list.splice(i, 1);
        } else {
          continue;
        }
      }
    },
    //选择节点入参
    // value代表选中的数据,key代表入参
    selectionOrigin(value, key) {
      let self = this;
      if (value != "") {
        this.selectionOriginDel(
          this.selectList,
          this.currentSelectedModel.id + "&" + key + "&"
        );
        this.selectList.push(
          this.currentSelectedModel.id + "&" + key + "&" + value
        );
        console.log("添加" + value);
        //md1
        if (this.currentSelectedModel.id.startsWith("UserDefined")) {
          let originData;
          for (let pq = 0; pq < this.nodeInfo.length; pq++) {
            $.each(this.nodeInfo[pq], function(name, value) {
              if (name == "tz_node_begin") {
                $.each(value, function(inname, invalue) {
                  originData = invalue;
                });
              }
            });
          }

          let s = originData[value.split("-")[0]];
          s = s.substring(2, s.length);

          self.cavans.setName(
            this.currentSelectedModel.id,
            value + "|" + s,
            "nodes"
          );
          this.currentSelectedModel.name = value + "|" + s;
        }

        //console.log(selectList);
      } else {
        this.selectionOriginDel(
          this.selectList,
          this.currentSelectedModel.id + "&" + key + "&"
        );
      }
    },
    // 网元能力条件里有个删除函数(修改)
    showNodeDel(text) {
      if (typeof this.clientNode.id == "undefined") {
        this.clientNode.id = "cavans_" + this.clientNode.name;
      }
      console.log(this.clientNode.id);
      let self = this;
      for (let i = 0; i < this.conditionList.length; i++) {
        $.each(this.conditionList[i], function(name, value) {
          console.log("name:" + name + "clientNode.id:" + self.clientNode.id);
          if (name == self.clientNode.id) {
            for (let j = 0; j < value.length; j++) {
              console.log(value[j]);
              if (value[j] == text) {
                if (value.length == 1) {
                  delete self.conditionList[i][name];
                } else {
                  if (j == 0) {
                    value.splice(0, 1);
                  } else {
                    value.splice(j, j);
                  }
                }
                self.showNode(self.clientNode.id);
                return;
              }
            }
          }
        });
      }
    }
  }
};
</script>
<style lang="scss">
.pform {
  display: block;
  margin: 0px;
  padding: 0px;
  line-height: 1.5;
  border: #ccc 1px solid;
  font: 12px Arial, Helvetica, sans-serif;
  margin: 5px 5px 0px 0px;
  border-radius: 4px;
}

.pform .form_title {
  background: #428bca;
  padding: 4px;
  color: #fff;
  border-radius: 3px 3px 0px 0px;
}

.pform .form_content {
  padding: 4px;
  background: #fff;
}

.pform .form_content table {
  border: 0px;
}

.pform .form_content table td {
  border: 0px;
}

.pform .form_content table .th {
  text-align: right;
  font-weight: bold;
}

.pform .form_btn_div {
  text-align: center;
  border-top: #ccc 1px solid;
  background: #f5f5f5;
  padding: 4px;
  border-radius: 0px 0px 3px 3px;
}

.pform select {
  width: 160px;
}
</style>
